home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vidlibp / vidgen.frm < prev    next >
Text File  |  1995-05-01  |  9KB  |  280 lines

  1. VERSION 2.00
  2. Begin Form VidGen 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Maintain "
  6.    ClientHeight    =   2205
  7.    ClientLeft      =   1860
  8.    ClientTop       =   2265
  9.    ClientWidth     =   6000
  10.    Height          =   2610
  11.    HelpContextID   =   245
  12.    Left            =   1800
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   2205
  17.    ScaleWidth      =   6000
  18.    Top             =   1920
  19.    Width           =   6120
  20.    Begin CommandButton cmdDelete 
  21.       Caption         =   "De&lete"
  22.       Height          =   465
  23.       HelpContextID   =   245
  24.       Left            =   3060
  25.       TabIndex        =   7
  26.       Top             =   1500
  27.       Width           =   1230
  28.    End
  29.    Begin CommandButton cmdDone 
  30.       Cancel          =   -1  'True
  31.       Caption         =   "&Done"
  32.       Height          =   465
  33.       HelpContextID   =   245
  34.       Left            =   4365
  35.       TabIndex        =   6
  36.       Top             =   1500
  37.       Width           =   1230
  38.    End
  39.    Begin CommandButton cmdUpdate 
  40.       Caption         =   "&Update"
  41.       Default         =   -1  'True
  42.       Height          =   465
  43.       HelpContextID   =   245
  44.       Left            =   1755
  45.       TabIndex        =   5
  46.       Top             =   1500
  47.       Width           =   1230
  48.    End
  49.    Begin CommandButton cmdAdd 
  50.       Caption         =   "&Add"
  51.       Height          =   465
  52.       HelpContextID   =   245
  53.       Left            =   450
  54.       TabIndex        =   4
  55.       Top             =   1500
  56.       Width           =   1230
  57.    End
  58.    Begin TextBox txtText 
  59.       BackColor       =   &H0000FFFF&
  60.       DataField       =   "GenText"
  61.       DataSource      =   "dtaGeneric"
  62.       Height          =   390
  63.       HelpContextID   =   245
  64.       Left            =   1395
  65.       MaxLength       =   50
  66.       TabIndex        =   1
  67.       Top             =   450
  68.       Width           =   4200
  69.    End
  70.    Begin TextBox txtCode 
  71.       BackColor       =   &H0000FFFF&
  72.       DataField       =   "GenCode"
  73.       DataSource      =   "dtaGeneric"
  74.       Height          =   390
  75.       HelpContextID   =   245
  76.       Left            =   450
  77.       MaxLength       =   1
  78.       TabIndex        =   0
  79.       Top             =   450
  80.       Width           =   645
  81.    End
  82.    Begin Data dtaGeneric 
  83.       Connect         =   ""
  84.       DatabaseName    =   "C:\VB\VIDLIB\VIDLIB.MDB"
  85.       Exclusive       =   0   'False
  86.       Height          =   270
  87.       Left            =   450
  88.       Options         =   0
  89.       ReadOnly        =   0   'False
  90.       RecordSource    =   "Genre"
  91.       Top             =   975
  92.       Width           =   5145
  93.    End
  94.    Begin Label lblText 
  95.       AutoSize        =   -1  'True
  96.       BackColor       =   &H00C0C0C0&
  97.       Caption         =   "Text:"
  98.       Height          =   195
  99.       Left            =   1395
  100.       TabIndex        =   3
  101.       Top             =   225
  102.       Width           =   450
  103.    End
  104.    Begin Label lblCode 
  105.       AutoSize        =   -1  'True
  106.       BackColor       =   &H00C0C0C0&
  107.       Caption         =   "Code:"
  108.       Height          =   195
  109.       Left            =   450
  110.       TabIndex        =   2
  111.       Top             =   225
  112.       Width           =   510
  113.    End
  114. End
  115. ' Subsystem: Edit
  116. ' Module:    VidGen.Frm
  117. ' Date:      01/02/94
  118. ' Author:    Richard Stauch
  119. ' Notes:
  120. ' This Generic form serves two tables for editing,
  121. ' Genre and Rating. For more details on how this is
  122. ' accomplished, see the Form_Load event.
  123.  
  124. Option Explicit
  125. DefInt A-Z
  126.  
  127. Sub cmdAdd_Click ()
  128. ' Add a new record to the table.
  129. ' First, make sure the user can enter new data.
  130.   cmdUpdate.Enabled = True
  131.   txtCode.Enabled = True
  132.   txtText.Enabled = True
  133. ' Display the current activity.
  134.   dtaGeneric.Caption = "Adding record."
  135. ' Add a blank record.
  136.   dtaGeneric.Recordset.AddNew
  137. ' Set the input focus on the first input-capable field.
  138.   txtCode.SetFocus
  139. End Sub
  140.  
  141. Sub cmdDelete_Click ()
  142. ' Delete the current record.
  143.   If Not CodeInUse(Left$(txtCode.Text, 1), Generic$) Then
  144.   ' This code is not in use.
  145.     dtaGeneric.Recordset.Delete ' Delete the record.
  146.     dtaGeneric.Refresh ' Rebuild the record set.
  147.     If dtaGeneric.Recordset.EOF And dtaGeneric.Recordset.BOF Then
  148.     ' The record set is empty, so disable text boxes and buttons.
  149.       cmdUpdate.Enabled = False
  150.       cmdDelete.Enabled = False
  151.       txtCode.Enabled = False
  152.       txtText.Enabled = False
  153.     ' Notify the user there are no records to edit.
  154.       dtaGeneric.Caption = "No valid record."
  155.     End If
  156.   Else
  157.   ' Notify user this code is in use.
  158.     Beep
  159.     GenericMsgBox (MBC_CODEINUSE)
  160.   End If
  161. End Sub
  162.  
  163. Sub cmdDone_Click ()
  164. ' Remove the Generic form from the display.
  165.   Unload VidGen
  166. End Sub
  167.  
  168. Sub cmdUpdate_Click ()
  169. ' Update the current record.
  170.   On Error GoTo UpdateError
  171.   If (txtCode.Text <> "") And (txtText.Text <> "") Then
  172.   ' There are no blanks in key fields, so update the record.
  173.     dtaGeneric.Recordset.Update
  174.   ' Make sure the user can delete records.
  175.     cmdDelete.Enabled = True
  176.   ' Rebuild the record set.
  177.     dtaGeneric.Refresh
  178.   ' Inform the user of the current operation.
  179.     dtaGeneric.Caption = "Editing record."
  180.   Else
  181.   ' Inform user that fields cannot be blank.
  182.     Beep
  183.     GenericMsgBox (MBC_NOBLANKS)
  184.   End If
  185. ' Set the input focus on the first input-capable field.
  186.   txtCode.SetFocus
  187.   Exit Sub
  188.  
  189. UpdateError:
  190. ' Inform the user there's a problem with the data.
  191.   Beep
  192.   GenericMsgBox (MBC_BADDATA)
  193.   If dtaGeneric.Caption = "Adding record." Then
  194.   ' Cancel the Add operation, if it's working.
  195.     dtaGeneric.Recordset.AddNew
  196.     dtaGeneric.Recordset.Refresh
  197.   End If
  198.   Exit Sub
  199. End Sub
  200.  
  201. Function CodeInUse (UseCode As String, CodeField As String) As Integer
  202. ' Open the Video table, and search for UseCode.
  203. Dim DB As Database ' Define the database object.
  204. Dim T As Dynaset   ' Define the table object.
  205. ' Open the current database, (Exclusive = False, Read-Only = True).
  206.   Set DB = OpenDatabase(PathName$, False, True)
  207. ' Use the Video table.
  208.   Set T = DB.CreateDynaset("Video")
  209. ' We use the FindFirst method to look up the UseCode,
  210. ' then reverse the logic of the NoMatch property.
  211.   If CodeField$ = "G" Then
  212.   ' The CodeField variable indicates (G)enre.
  213.     T.FindFirst "GenCode = '" + Left$(UseCode$, 1) + "'"
  214.     CodeInUse% = Not T.NoMatch
  215.   ElseIf CodeField$ = "R" Then
  216.   ' The CodeField variable indicates (R)ating.
  217.     T.FindFirst "RatCode = '" + Left$(UseCode$, 1) + "'"
  218.     CodeInUse% = Not T.NoMatch
  219.   Else
  220.   ' The CodeField variable is invalid.
  221.     CodeInUse% = False
  222.   End If
  223. ' We're finished, so close the database and table.
  224.   T.Close
  225.   DB.Close
  226. End Function
  227.  
  228. Sub Form_Load ()
  229. ' Load the form, and alter the text fields according to the table
  230. ' in use. We do this before the Show method.
  231. ' First, make sure the Data control is using the right database.
  232.   dtaGeneric.DatabaseName = PathName$
  233. ' Set captions for Genre or Rating tables.
  234.   If Generic$ = "G" Then
  235.   ' We're using the Genre table.
  236.     VidGen.Caption = VidGen.Caption & "Genre Data"
  237.     dtaGeneric.RecordSource = "Genre"
  238.     txtCode.DataField = "GenCode"
  239.     txtText.DataField = "GenText"
  240.   ElseIf Generic$ = "R" Then
  241.   ' We're using the Rating table.
  242.     VidGen.Caption = VidGen.Caption & "Rating Data"
  243.     dtaGeneric.RecordSource = "Rating"
  244.     txtCode.DataField = "RatCode"
  245.     txtText.DataField = "RatText"
  246.   End If
  247. ' Refresh the record set.
  248.   dtaGeneric.Refresh
  249. ' Show the form on the display, so we can set input focus.
  250.   VidGen.Show
  251.   If dtaGeneric.Recordset.EOF And dtaGeneric.Recordset.BOF Then
  252.   ' The table is empty, so disable the update function.
  253.     cmdUpdate.Enabled = False
  254.     cmdDelete.Enabled = False
  255.     txtCode.Enabled = False
  256.     txtText.Enabled = False
  257.     dtaGeneric.Caption = "No valid record."
  258.   ' The user can still Add records.
  259.     cmdAdd.SetFocus
  260.   Else
  261.   ' There are records, so we default to Edit mode.
  262.     dtaGeneric.Caption = "Editing